package Demo.Interfaces;

/**
 * @className: Student
 * @author: 芃
 * @description: 实现Comparable接口完成比较
 * @date: 2023/8/17 12:17
 */
public class Student implements Comparable<Student>{
    public String name;
    public int age;
    public double score;

    public Student(String name, int age, double score) {
        this.name = name;
        this.age = age;
        this.score = score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", score=" + score +
                '}';
    }


    //谁调用CompareTo谁就是this
    @Override
    public int compareTo(Student o) {
        if (this.score > o.score){
            return 1;
        }else if (this.score == o.score){
            return 0;
        }else {
            return -1;
        }
    }
}
